import type { AddressItem } from '@/types/address'
import { http } from '@/utils/http'

/**
 * 添加收货地址
 * @param data 请求参数
 */
export const addMemberAddress = (data: AddressItem) => {
  return http({
    method: 'POST',
    url: '/api/memberAddress/addMemberAddress',
    data,
  })
}

/**
 * 获取收货地址列表
 */
export const listMemberAddress = () => {
  return http<AddressItem[]>({
    method: 'GET',
    url: '/api/memberAddress/listMemberAddress',
  })
}

/**
 * 获取收货地址详情
 * @param id 地址id(路径参数)
 */
export const selectMemberAddressById = (memberAddressId: number) => {
  return http<AddressItem>({
    method: 'GET',
    url: `/api/memberAddress/selectMemberAddressById`,
    data: { memberAddressId },
  })
}

/**
 * 修改收货地址
 * @param id 地址id(路径参数)
 * @param data 表单数据(请求体参数)
 */
export const updateMemberAddress = (data: AddressItem) => {
  return http({
    method: 'POST',
    url: `/api/memberAddress/updateMemberAddress`,
    data,
  })
}

/**
 * 删除收货地址
 * @param id 地址id(路径参数)
 */
export const deleteMemberAddress = (memberAddressId: number) => {
  return http({
    method: 'POST',
    url: `/api/memberAddress/deleteMemberAddress`,
    data: { memberAddressId },
  })
}
